package xyz.yuanjilu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import xyz.yuanjilu.dao.GroupInfoDao;
import xyz.yuanjilu.dao.GroupSalesDao;
import xyz.yuanjilu.dao.GroupWebSiteDao;
import xyz.yuanjilu.entity.GroupInfoEntity;
import xyz.yuanjilu.entity.GroupSalesEntity;
import xyz.yuanjilu.entity.GroupWebSiteEntity;
import xyz.yuanjilu.service.GroupInfoService;



@Service("groupInfoService")
public class GroupInfoServiceImpl implements GroupInfoService {
	@Autowired
	private GroupInfoDao groupInfoDao;
	@Autowired
	private GroupWebSiteDao groupWebSiteDao;
	@Autowired
	private GroupSalesDao groupSalesDao;
	
	@Override
	public GroupInfoEntity queryObject(Long id){
		return groupInfoDao.queryObject(id);
	}
	
	@Override
	public List<GroupInfoEntity> queryList(Map<String, Object> map){
		return groupInfoDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return groupInfoDao.queryTotal(map);
	}
	
	@Override
	public void save(GroupInfoEntity groupInfo){
		groupInfoDao.save(groupInfo);
	}
	
	@Override
	public void update(GroupInfoEntity groupInfo){
		groupInfoDao.update(groupInfo);
	}
	
	@Override
	public void delete(Long id){
		groupInfoDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		groupInfoDao.deleteBatch(ids);
	}

    @Override
    public void bindWebsite(String groupId, String[] websiteIds) {
        groupWebSiteDao.deleteByGroupId(groupId);
        for (String websiteId : websiteIds) {
            GroupWebSiteEntity groupWebSiteEntity=new GroupWebSiteEntity();
            groupWebSiteEntity.setGroupId(groupId);
            groupWebSiteEntity.setWebSiteId(websiteId);
            groupWebSiteDao.save(groupWebSiteEntity);
        }
        
    }

    @Override
    public void bindSales(String groupId, String[] salesIds) {
        groupSalesDao.deleteByGroupId(groupId);
        for (String salesId : salesIds) {
            GroupSalesEntity groupSalesEntity=new GroupSalesEntity();
            groupSalesEntity.setGroupId(groupId);
            groupSalesEntity.setSalesId(salesId);
            groupSalesDao.save(groupSalesEntity);
        }
        
    }

	@Override
	public String[] getKeywordsBysales(Long Id) {
		String keywordsBysales = this.getKeywordBysales(Id);
		return keywordsBysales.split(",");
	}
	@Override
	public String getKeywordBysales(Long Id) {
		String keywordsBysales = groupInfoDao.getKeywordsBysales(Id);
		return keywordsBysales+"";
	}
	
	
	
}
